import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

// 处理路由跳转到当前页报错
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch((err) => err)
}

const routes = [
  {
    path: '/',
    redirect: '/movie/playing'
  },
  {
    path: '/movie',
    component: () => import('@/views/movie/index.vue'),
    children: [
      {
        path: 'playing',
        component: () => import('@/views/movie/Playing.vue')
      },
      {
        path: 'future',
        component: () => import('@/views/movie/Future.vue')
      },
      {
        path: 'mdetail',
        component: () => import('@/views/movie/Detail.vue')
      }
    ]
  },
  {
    path: '/cinema',
    component: () => import('@/views/cinema/index.vue'),
    children: [
      {
        path: 'clist',
        component: () => import('@/views/cinema/Cinema.vue')
      },
      {
        path: 'cdetail',
        component: () => import('@/views/cinema/Detail.vue')
      }
    ]
  },
  {
    path: '/news',
    component: () => import('@/views/news/index.vue')
  },
  {
    path: '/my',
    component: () => import('@/views/my/index.vue')
  },
  {
    path: '/city',
    component: () => import('@/views/city/index.vue')
  },
  {
    path: '/login',
    component: () => import('@/views/login/index.vue')
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

export default router
